#include "BinOp.h"
#include "IVisitor.h"

BinOp::BinOp(const exprTypePtr& left, int op, const exprTypePtr& right, int nodeId):
    exprType(nodeId),
    _left(left),
    _op(op),
    _right(right)
{
}
    
BinOp::~BinOp()
{
    
}
    
QString BinOp::type() const
{
    return "BinOp";
}
    

exprTypePtr BinOp::left()
{
    return _left;
}

void BinOp::setLeft(const exprTypePtr& left)
{
    _left = left;
}

int BinOp::op()
{
    return _op;
}

void BinOp::setOp(int op)
{
    _op = op;
}

exprTypePtr BinOp::right()
{
    return _right;
}

void BinOp::setRight(const exprTypePtr& right)
{
    _right = right;
}

    
QString BinOp::toString() const
{
    return QString("BinOp[left=%1, op=%2, right=%3]").
                arg(_left ? _left->toString():"").
                arg(_op).
                arg(_right ? _right->toString():"");
}
    
void BinOp::accept(IVisitor* visitor, const SimpleNodePtr& node)
{
    visitor->visitBinOp(node.dynamicCast<BinOp>());
}
    
void BinOp::traverse(IVisitor* visitor)
{
    if (_left != NULL)
        _left->accept(visitor, _left);
    if (_right != NULL)
        _right->accept(visitor, _right);
}